package Messages;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Arrays;

import ocsf.server.ConnectionToClient;

import client.LibaryMain;

import pdf.PDFTrans;

/**
 * this class implements the librarian edit buying date in db
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class MessageGiveBook {
	private ConnectionToClient client2;
	  byte[] byteArray=null;
	  
	
	 
	 

	public MessageGiveBook(ConnectionToClient client2, String str) throws IOException {
			super();
			this.client2=client2;
			givebook(str);

	}

 

	

	private void givebook(String str) throws IOException {
		  Socket socket = new Socket(client2.getInetAddress(), PDFTrans.PORT);  
	      // ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());  
	       ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());  
	       File file = new File("C:/"+str);
	       oos.writeObject(file.getName());  
	       
	       FileInputStream fis = new FileInputStream(file);  
	       byte [] buffer = new byte[PDFTrans.BUFFER_SIZE];  
	       Integer bytesRead = 0;  
	 
	       while ((bytesRead = fis.read(buffer)) > 0) {  
	           oos.writeObject(bytesRead);  
	           oos.writeObject(Arrays.copyOf(buffer, buffer.length));  
	       }  
	 
	       oos.close();  
	    //   ois.close(); 
	      // socket.close();
	}

	
      
	  
}
